home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-08 | 6.1 KB | 231 lines | [TEXT/PJMM] |
- {****************************************************}
- {}
- { CGameApp.p }
- {}
- { Application class, optimized to the needs of gameplay. }
- {}
- { Copyright © 1996 by Patrick C Hew. All rights reserved. }
- {}
- {****************************************************}
-
-
- unit CGameApp;
-
- interface
-
- uses
- TCL, GameIntf;
-
- implementation
-
-
- {****************************************************}
- {}
- { IGameApp }
- {}
- { Initializes a Game Application object. }
- {}
- {****************************************************}
-
- procedure CGameApp.IGameApp (extraMasters: Integer;
- aRainyDayFund: Longint;
- aCriticalBalance: Longint;
- aToolboxBalance: Longint);
-
- begin { IGameApp }
- IApplication(extraMasters, aRainyDayFund, aCriticalBalance, aToolboxBalance);
-
- { Start as a normal, everyday Macintosh application. }
- isInGameMode := FALSE;
-
- { Default to not being friendly in animation mode. May want to store this as a preference. }
- isBkgdFriendlyInGameMode := FALSE;
- end; { IGameApp }
-
-
- {****************************************************}
- {}
- { MakeSwitchboard }
- {}
- { Creates the single Game Switchboard object used by the application. }
- { We store a pointer for our own use. }
- {}
- {****************************************************}
-
- procedure CGameApp.MakeSwitchboard;
-
- var
- theSwitchboard: CGameSwitchboard;
-
- begin { MakeSwitchboard }
- new(theSwitchboard);
- theSwitchboard.IGameSwitchboard;
- itsSwitchboard := theSwitchboard;
- itsGameSwitchboard := theSwitchboard;
- end; { MakeSwitchboard }
-
-
- {****************************************************}
- {}
- { Idle }
- {}
- { It is expected that there is a Game Director, handling game animation etc. }
- { in its Dawdle method. This method streamlines the call during gameplay. }
- {}
- { It is assumed that during gameplay, the following hold :- }
- { 1 There are no memory emergencies to correct, so the Rainy Day memory }
- { fund does not need to be reset. It will, in any case, be reset when we }
- { leave game mode. }
- { 2 The Game Director is the gopher. }
- { 3 Only the Game Director needs to receive a Dawdle method. Reasonable, }
- { unless you have a special director reporting to the Game Director; for }
- { instance, a window set up for controls. In such a case, you may want }
- { to make the gopher send a Dawdle message to its supervisor. }
- { 4 There are no other Dawdle chores to perform. }
- {}
- {****************************************************}
-
- procedure CGameApp.Idle (macEvent: EventRecord);
-
- var
- maxSleep: LongInt;
-
- begin { Idle }
- if not isInGameMode then begin
- inherited Idle(macEvent);
- end { if }
- else begin
- maxSleep := MAXLONGINT;
-
- gGopher.Dawdle(maxSleep);
-
- gSleepTime := maxSleep;
- end; { else }
- end; { Idle }
-
-
- {****************************************************}
- {}
- { Process1Event }
- {}
- { Streamlined processing of events during gameplay. }
- {}
- { It is assumed that during gameplay, the following hold :- }
- { 1 The desktop does not need to be cleaned up. This holds if there are no }
- { floating windows. }
- { 2 There are no urgent chores to be performed. }
- { 3 There is no switching to or from desk accessories. }
- {}
- {****************************************************}
-
- procedure CGameApp.Process1Event;
-
- begin { Process1Event }
- if not isInGameMode then begin
- inherited Process1Event;
- end { if }
- else begin
- itsSwitchboard.ProcessEvent;
- end; { else }
- end; { Process1Event }
-
-
- {****************************************************}
- {}
- { DoCommand }
- {}
- { Turn off game mode before quitting. }
- {}
- {****************************************************}
-
- procedure CGameApp.DoCommand (theCommand: LongInt);
-
- begin { DoCommand }
- if theCommand = cmdQuit then begin
- isInGameMode := FALSE;
- itsGameSwitchboard.SetBackgroundFriendly(TRUE);
- end; { if }
- inherited DoCommand(theCommand);
- end; { DoCommand }
-
-
- {****************************************************}
- {}
- { GetInGameMode }
- {}
- { Return whether or not we are in game mode. }
- {}
- {****************************************************}
-
- function CGameApp.GetInGameMode: Boolean;
-
- begin { GetInGameMode }
- GetInGameMode := isInGameMode;
- end; { GetInGameMode }
-
-
- {****************************************************}
- {}
- { BeginGameMode }
- {}
- { Configure for fast event processing. }
- {}
- {****************************************************}
-
- procedure CGameApp.BeginGameMode;
-
- begin { BeginGameMode }
- isInGameMode := TRUE;
- itsGameSwitchboard.SetInGameMode(TRUE);
- itsGameSwitchboard.SetBackgroundFriendly(isBkgdFriendlyInGameMode);
- end; { BeginGameMode }
-
-
- {****************************************************}
- {}
- { EndGameMode }
- {}
- { Return to normal event processing. }
- {}
- {****************************************************}
-
- procedure CGameApp.EndGameMode;
-
- begin { EndGameMode }
- isInGameMode := FALSE;
- itsGameSwitchboard.SetInGameMode(FALSE);
- itsGameSwitchboard.SetBackgroundFriendly(TRUE);
- end; { EndGameMode }
-
-
- {****************************************************}
- {}
- { GetBkgdFriendlyInGameMode }
- {}
- { Get the state of background friendliness in game mode. }
- {}
- {****************************************************}
-
- function CGameApp.GetBkgdFriendlyInGameMode: Boolean;
-
- begin { GetBackgroundFriendly }
- GetBkgdFriendlyInGameMode := isBkgdFriendlyInGameMode;
- end; { GetBkgdFriendlyInGameMode }
-
-
- {****************************************************}
- {}
- { SetBkgdFriendlyInGameMode }
- {}
- { Set the background friendliness in game mode. }
- {}
- {****************************************************}
-
- procedure CGameApp.SetBkgdFriendlyInGameMode (aBkgdFriendlyInGameMode: Boolean);
-
- begin { SetBkgdFriendlyInGameMode }
- isBkgdFriendlyInGameMode := aBkgdFriendlyInGameMode;
- end; { SetBkgdFriendlyInGameMode }
-
-
- end. { CGameApp }